package main

import (
	"github.com/streadway/amqp"
	"log"
	"os"
	"rabbitmq"
)

func main() {

	conn := rabbitmq.NewConn()
	defer conn.Close()

	channel, err := conn.Channel()
	rabbitmq.FailOnError(err, "Channel err")

	body := rabbitmq.BodyFrom(os.Args)
	err = channel.Publish("normal_exchange", rabbitmq.SeverityFrom(os.Args), true, false, amqp.Publishing{
		ContentType: "text/plain",
		Body:        []byte(body),
	})

	log.Printf("Publish success")
	rabbitmq.FailOnError(err, "Publish err:")

	notify := make(chan amqp.Return, 1)
	channel.NotifyReturn(notify)

	go func() {
		for n := range notify {
			log.Printf("notify:%v", n)
			log.Printf("Exchange:%s, RoutingKey:%s, MessageId:%s, ReplyText:%s, Body:%s", n.Exchange, n.RoutingKey, n.MessageId, n.ReplyText, n.Body)
		}
	}()
}
